package controllers

import (
	"gitee.com/tangrx/go-admin/app"
	"gitee.com/tangrx/go-admin/models"
	"github.com/gin-gonic/gin"
	"log"
)

func init() {
	app.Any("/api/sys/log", func(c *gin.Context) {

		var json models.SearchForm
		if err := c.ShouldBindJSON(&json); err != nil {
			c.JSON(200, gin.H{"error": err.Error()})
			return
		}

		c.JSON(200, models.GetLogList4Pager(json))
	})

	app.Any("/api/sys/log/delete", func(c *gin.Context) {

		var json map[string]int

		if err := c.ShouldBindJSON(&json); err != nil {
			c.JSON(200, gin.H{"error": err.Error()})
			return
		}
		data := models.DeleteLog(json["id"])
		if data == 0 {
			c.JSON(200, gin.H{"status": "100",
				"data": nil,
				"msg":  "数据不存在！",
			})
			return
		}
		log.Println(data)
		c.JSON(200, gin.H{"status": "200",
			"data": nil,
			"msg":  "删除成功！",
		})
	})
}
